﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using DefLib;

namespace GameUI
{
    public class Board:UIunit
    {
        int width_unit;
        int height_unit;
        List<Oco> l_ocomau;
        List<Oco> l_oco;

        public void create(float x, float y, int width, int height, int w_u, int h_u)
        {
            _x = x;
            _y = y;
            _w = width;
            _h = height;
            width_unit = w_u;
            height_unit = h_u;
            int unit_w = _w/width_unit;
            int unit_h = _h/height_unit;
            l_ocomau = new List<Oco>();
            Oco o_b = new Oco();
            o_b.create(Oco.black,0,0,_w/width_unit,_h/height_unit);
            Oco o_w = new Oco();
            o_w.create(Oco.white,0,0,_w/width_unit,_h/height_unit);
            l_ocomau.Add(o_b);
            l_ocomau.Add(o_w);

            l_oco = new List<Oco>();
            for (int i = 0; i < width_unit ; i++)
            {
                for(int j=0;j< height_unit;j++)
                {
                    if (((((i+1) % width_unit) * (j % height_unit) % 2)==0)&&(((i % width_unit) * ((j+1) % height_unit) % 2)==0))
                    {
                        Oco o_bc = l_ocomau[Oco.black].CloneCO(i * unit_w, j * unit_h, unit_w, unit_h);
                        l_oco.Add(o_bc);
                    }
                    else
                    {
                        l_oco.Add(l_ocomau[Oco.white].CloneCO(i * unit_w, j * unit_h, unit_w, unit_h));
                    }
                }
            }
        }
        public override void update(float x, float y, int w, int h)
        {
            for (int i = 0; i < width_unit * height_unit; i++)
            {
                l_oco[i].update(0,0,0,0);
            }
        }
        public override void draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < width_unit * height_unit; i++)
            {
                l_oco[i].draw(spriteBatch);
            }
        }

    }
}
